package com.wangtao.netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;

import java.util.stream.IntStream;


public class NettyByteBuf{
    public static void main(String[] args) {
        ByteBuf buffer = Unpooled.buffer(10);
        IntStream.rangeClosed(0,buffer.capacity()-1).forEach(i->{
            buffer.writeByte(i);
        });

//        for (int i = 0; i <buffer.capacity() ; i++) {
//            System.out.println(buffer.getByte(i));
//        }

        ByteBuf buf = Unpooled.copiedBuffer("你好abc", CharsetUtil.UTF_8);

        if (buf.hasArray()) {
            byte[] array = buf.array();
            System.out.println(new String(array,CharsetUtil.UTF_8));
        }
    }
}
